<style fiType="text/css">
<!--
.basicText {
	font-family: Verdana, Geneva, sans-serif;
}
.blue {
	color: #000080;
}
green {
	color: #008040;
}
.green {
	color: #008040;
}
.red {
	color: #F00;
}
.magenta {
	color: #F0F;
}
.light-blue {
	color: #66F;
}
.light-green {
	color: #090;
}
-->
</style>
<h1 align="center" class="basicText">Intro to Netlet Programming</h1>
<p class="basicText">A <strong><em>mogram</em></strong> is a <em>service model</em> of <strong><em>a dynamic service federation</em></strong>. Two types of mograms are distinguished: <em><strong>imperative exertions</strong></em> and <em><strong>declarative context models</strong></em>. <em>Mogram scripts</em> executed by the service network dynamically are called<em><strong> </strong></em><strong><em>netlets</em></strong>. See  <a href="http://sorcersoft.org/project/site/tutorials.html">SORCER tutorials</a> </p>
<p class="basicText">A <em>task exertion</em> is comprised of <em>name</em>, service <em>signature</em> (<code>sig</code>), and <em>service data</em> (<code>context</code>). A context model is an associative memory with <em>paths</em> (like file paths, e.g., <code>"arg/x1"</code>) that create a service namespace along with their respective values.</p>
<p class="basicText">For example a <em>service</em> <code>f4=x1*x2;</code> can be represented by the following task: </p>
<blockquote>
  <p class="basicText"><code>Task f4 = <span class="light-green">task</span>("f4", <span class="red">sig</span>("<span class="red">multiply</span>", <span class="red">Multiplier.class</span>), <br />
  	    	</code><span class="light-blue"><code>&nbsp; &nbsp; context</code></span><code>("multiply", <span class="light-blue">inEnt</span>("arg/x1", 10.0),
  	    	<span class="light-blue">inEnt</span>("arg/x2", 50.0), <span class="light-blue"><br /> &nbsp; &nbsp; outEnt</span>("result/y1")));  </code></p>
</blockquote>
<p class="basicText">In the above task the operation is  specified by  <code>"multiply"</code> which is defined by the service fiType <code>Multiplier.class</code>. Service types are Java <em>interface types</em> that define the functionality  of services. Three basic types of context args are distinguished: <code>inEnt</code>, <code>outEnt</code>, and <code>inoutEnt</code>. Additional attributes identifying the service, for example a <em>service name</em>,  can be associated with the operator <code>sig</code> using the <code>prvName</code> operator.  </p>
<p class="basicText">A <em>job exertion</em> is a hierarchical composition of exertion tasks, blocks, and other jobs that defines a service composition. For example, the service composition
  <code>f1(f2(f4,f5),f3)</code> can be defined as follows: <br />
  execution of <code>f2</code> (<code>f4=x1*x2 and f5=x3+x4</code> in parallel) and then <code>f3=f4-f5</code>.</p>
<blockquote>
  <p class="basicText"> <code>Task f4 = <span class="blue"><span class="green"><span class="light-green">task</span></span></span>("f4", <span class="red">sig</span>("<span class="red">multiply</span>", <span class="red">Multiplier.class</span>), <br />
    <span class="light-blue"> &nbsp; &nbsp; context</span>("multiply", <span class="blue"><span class="magenta">inEnt</span></span>("arg/x1", 10.0), <span class="blue"><span class="magenta">inEnt</span></span>("arg/x2", 50.0),
    <span class="blue"><span class="light-blue"> <br /> 
    &nbsp; &nbsp; </span></span><span class="magenta">result</span>("result/y1")));</code>  </p>
  <p class="basicText"><code>Task f5 = <span class="green"><span class="light-green">task</span></span>("f5", <span class="red">sig</span>("<span class="red">add</span>", <span class="red">Adder.class</span>), <br />
    <span class="light-blue"> &nbsp; &nbsp; context</span>("add", <span class="blue"><span class="magenta">inEnt</span></span>("arg/x3", 20.0), <span class="blue"><span class="magenta">inEnt</span></span>("arg/x4", 80.0),
    <span class="blue"> <br /> 
    &nbsp; &nbsp; </span><span class="magenta">result</span></span>("result/y2")));</code></p>
  <p class="basicText">
    
    <code>Task f3 = <span class="green"><span class="light-green">task</span></span>("f3", <span class="red">sig</span>("<span class="red">subtract</span>", <span class="red">Subtractor.class</span>), <br />
    <span class="light-blue"> &nbsp; &nbsp; context</span>("subtract", <span class="blue"><span class="magenta">inEnt</span></span>("arg/x5"), <span class="blue"><span class="magenta">inEnt</span></span>("arg/x6"),
      <span class="blue"><span class="light-blue"><br /> 
      &nbsp; &nbsp; </span></span><span class="magenta">result</span>("result/y3")));</code>  </p>
  <p class="basicText"><code>Job f1 = <span class="green"><span class="light-green">job</span></span>("f1", <br />
    <span class="green"><span class="light-green">  &nbsp; &nbsp; job</span></span>("f2", f4, f5, <span class="blue">strategy</span>(Flow.PAR, Access.PULL)), <br /> 
    &nbsp; &nbsp; f3,   <br />
    <span class="magenta"> &nbsp; &nbsp; pipe</span>(<span class="blue"><span class="magenta">outPoint</span></span>(f4, "result/y1"), <span class="blue"><span class="magenta">inPoint</span></span>(f3, "arg/x5")),
    <br />
    <span class="magenta"> &nbsp; &nbsp; pipe</span>(<span class="blue"><span class="magenta">outPoint</span></span>(f5, "result/y2"), <span class="blue"><span class="magenta">inPoint</span></span>(f3, "arg/x6")));</code>  </p>
</blockquote>
<p class="basicText">A job has a <em>name</em>, a <em>strategy</em> for executing its components, and <em>pipes</em> for data flow between the task service contexts.
  
  To execute the exertion  the <code>exert</code> operator is called: </p>
<blockquote>
  <p class="basicText"><code>Exertion out = exert(f1);</code>  </p>
</blockquote>
<p class="basicText">To get a <em>context value</em>, for example the value <code>&quot;result/y3&quot;</code> in the context of task <code>f3</code>, call the <code>get</code> operator: </p>
<blockquote>
  <p class="basicText"><code>get(context(out), "f1/f3/result/y3");</code></p>
</blockquote>

<p class="basicText">
A  <em>block</em> is a concatenation of exertions with control-flow exertions to define branching and looping for service-oriented algorithmic logic.
</p>

<p class="basicText">A <strong><em>context model</em></strong> is a <em>collection of functional compositions </em>as model args with dependent args (<span class="magenta"><code>inPaths</code></span>) that declares <strong><em>a dynamic service federation</em></strong>. The context model for the above exertion job f1 can be defined declaratively as follows: </p>

<blockquote>
  <p><code>
      Model mo = <span class="light-green">model</span>(<br />
     </code><code><span class="light-blue"> &nbsp; &nbsp; </span><span class="magenta">inEnt</span>("arg/x1", 10.0d), <span class="magenta">inEnt</span>("arg/x2", 50.0d),
    <span class="magenta"> <br /> 
    &nbsp; &nbsp; inEnt</span>("arg/x3", 20.0d), <span class="magenta">inEnt</span>("arg/x4", 80.0d),
    <br /> &nbsp; &nbsp; <span class="light-blue">proc</span>(<span class="red">sig</span>("<span class="red">multiply</span>", <span class="red">Multiplier.class</span>, <span class="magenta">result</span>("result/y1",
    <span class="magenta"><br /> &nbsp; &nbsp; &nbsp; &nbsp; inPaths</span>("arg/x1", "arg/x2")))),
    <span class="light-blue"> <br /> 
    &nbsp; &nbsp; proc</span>(<span class="red">sig</span>("<span class="red">add</span>", <span class="red">Adder.class</span>, <span class="magenta">result</span>("result/y2",
    <span class="magenta">  <br /> &nbsp; &nbsp; &nbsp; &nbsp; inPaths</span>("arg/x3", "arg/x4")))),
    <span class="light-blue"> <br /> &nbsp; &nbsp; proc</span>(<span class="red">sig</span>("out", "<span class="red">subtract</span>", <span class="red">Subtractor.class</span>, <span class="magenta"> result</span>("result/y3",
    <span class="magenta"> <br /> &nbsp; &nbsp; &nbsp; &nbsp; inPaths</span>("result/y1", "result/y2")))),
  <span class="magenta"> <br /> &nbsp; &nbsp; response</span>("out", "result/y1", "result/y2", "result/y3"));</code></p>
</blockquote>
<p class="basicText">To evaluate a model call </p>
<blockquote>
  <p class="basicText"><code>Context cxt = response(mo); </code>and for a value, for example <code>&quot;result/y3&quot;</code>, <code>get(cxt, &quot;result/y3&quot;</code>);</p>
</blockquote>
<p class="basicText">See more at <a href="http://sorcersoft.org/project/site/tutorials.html">SORCER tutorials</a> </p>
<p class="basicText">To use classes that come from external providers in your code you can dynamically load a jar file by using the following declaration.
    The jar files specified this way will be loaded from external http code servers (websters).
</p>
<p class="basicText">
    <span class="green"><span class="light-green"><code>@Load(group='xxxxx.xxxxxx', module='yyyy', version='vv.vv' [,classifier='zz'])</code></span></span>
    - a jar file that will be loaded from local or remote maven repository <br>
    <span class="green"><span class="light-green"><code>@Load('group:module[:fiType:classifier]:version')</code></span></span>
    - in a shorter notation
</p>
<p class="basicText">If you want to use these external classes in the elements that are being sent to remote providers please use the @Codebase annotation instead of @Load:
</p>
<p class="basicText">
    <span class="green"><span class="light-green"><code>@Codebase(group='xxxxx.xxxxxx', module='yyyy', version='vv.vv' [,classifier='zz'])</code></span></span>
    - a jar file that will be loaded from local or remote maven repository <br>
    <span class="green"><span class="light-green"><code>@Codebase('group:module[:fiType:classifier]:version')</code></span></span>
    - in a shorter notation
</p>






